// 9+(3-1)*3+10/2
// 931-3*+102/+

// 9 + 10 * 2  => 9102*+
// 9 + 10 - 2 => 9 10 + 2 -


namespace a {
  function generateTokens (exprStr: string) {
    let tokens: Array<string> = []
    let num = ""
    for (let i of exprStr) {
      if (i == " ") {
        continue
      }
      if (["+", "-", "*", "/", "(", ")"].indexOf(i) > -1) {
        if (num.length > 0) {
          tokens.push(num)
          num = ""
        }
        tokens.push(i)
      } else {
        num += i
      }
    }
    if (num.length > 0) {
      tokens.push(num)
    }
  
    return tokens
  }
  
  function transform (exprStr: string) {
    let tokens = generateTokens(exprStr)
    let output = ""
    let tokenStack = []
    for (let i = 0; i < tokens.length; i++) {
      let token = tokens[i]
      if (["+","-","*","/"].indexOf(token) > -1) {
        tokenStack.push(token)
      } else {
        output += token
        while (tokenStack.length > 0) {
          output += tokenStack.pop()
        }
  
      }
    }
    return output
  }
  
  function main () {
    let str = "9 + 10 - 2 * 5" // 9 10 + 2 5 * -
    let res = transform(str)
    console.log(res)
  }
  
  main()
  
  
  
}
